import React from 'react'
import PureRenderMixin from 'react-addons-pure-render-mixin'
//获取本地数据库的方法
import LocalStore from '../util/localStore.js';
//key值
import {CITYNAME} from '../config/localStoreKey.js';
//redux
import {bindActionCreators} from 'redux';
import {connect} from 'react-redux'
//action
import * as userInfoActionsFormOtherFile from '../actions/userinfo.js'

class App extends React.Component {
    constructor(props, context) {
        super(props, context);
        this.state={
            initDone:false
        }
        this.shouldComponentUpdate = PureRenderMixin.shouldComponentUpdate.bind(this);
    }
    render() {
        return (
            <div>
               {
                this.state.initDone ? this.props.children :<div>加载中...</div>
               }
            </div>
        )
    }
    //组件加载完成
    componentDidMount() {
        //从localstorerage里面获取城市
        let cityName = LocalStore.getItem(CITYNAME);
        if(cityName==null){
            cityName="北京"
        }
        //将城市信息存储到Redux中(
        // //console.log(this.props)connect连接后就可以直接在props中拿到绑定好action函数)
        this.props.userInAction.updata({
            cityName:cityName
        })
        this.setState({
            initDone:true
        })
    }
}
/*-------------------------Redux的连接--------------------------------*/
//返回组件需要的数据
function mapStateToProps (state) {
        return{

        } 
} 
//返回组件需要的action 
function mapDispatchToProps(dispatch) {
    return{
        userInAction:bindActionCreators(userInfoActionsFormOtherFile,dispatch)
    }
}
export default connect(mapStateToProps,mapDispatchToProps)(App)
